/*******************************************************************************
 * Copyright (c) 2010 Mikhail Garber.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License (LGPL)
 * which accompanies this distribution
 * 
 * Contributors:
 *     Mikhail Garber - initial API and implementation
 ******************************************************************************/
package plumber.coordinator;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import plumber.common.WorkItem;
import plumber.common.WorkItem.Status;
import plumber.context.ContextConverter;
import plumber.context.DefaultContextConverter;

/**
 * parent abstract class for several Coordinator implementations
 * @author mgarber
 *
 */
public class AbstractCoordinator {

	protected ContextConverter contextConverter = new DefaultContextConverter();
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	public void setContextConverter(ContextConverter contextConverter) {
		this.contextConverter = contextConverter;
	}

	/**
	 * factory method to produce a new WorkItem from this information
	 * @param context
	 * @param flowName
	 * @param nextStepId
	 * @param scheduled
	 * @param requestId
	 * @param namespace
	 * @return new WorkItem
	 */
	protected WorkItem makeNewItem(String context, String flowName, String nextStepId, Date scheduled,
			String requestId, String namespace) {
				WorkItem newItem = new WorkItem();
				newItem.setContext(context);
				newItem.setFlowStepId(nextStepId);
				newItem.setRequestId(requestId);
				newItem.setStatus(Status.AVAILABLE);
				newItem.setScheduled(scheduled);
				newItem.setFlowName(flowName);
				newItem.setNamespace(namespace);
				return newItem;
			}

}
